<?php

function sql_safe($value)
{
  // Stripslashes
  if (get_magic_quotes_gpc())
    $value = stripslashes($value);
  // Remove \r
  $value = eregi_replace("\r\n","\n",$value);
  // Strip tags
  $value = strip_html_tags(trim($value));
  // Encode special html entities
  $value = htmlspecialchars($value, ENT_QUOTES);
  // Escape the string
  $value = mysql_real_escape_string($value);
  return $value;
}

function strip_html_tags( $text )
{
    $text = preg_replace(
        array(
          // Remove invisible content
            '@<head[^>]*?>.*?</head>@siu',
            '@<style[^>]*?>.*?</style>@siu',
            '@<script[^>]*?.*?</script>@siu',
            '@<object[^>]*?.*?</object>@siu',
            '@<embed[^>]*?.*?</embed>@siu',
            '@<applet[^>]*?.*?</applet>@siu',
            '@<noframes[^>]*?.*?</noframes>@siu',
            '@<noscript[^>]*?.*?</noscript>@siu',
            '@<noembed[^>]*?.*?</noembed>@siu',
          // Add line breaks before and after blocks
            '@</?((address)|(blockquote)|(center)|(del))@iu',
            '@</?((div)|(h[1-9])|(ins)|(isindex)|(p)|(pre))@iu',
            '@</?((dir)|(dl)|(dt)|(dd)|(li)|(menu)|(ol)|(ul))@iu',
            '@</?((table)|(th)|(td)|(caption))@iu',
            '@</?((form)|(button)|(fieldset)|(legend)|(input))@iu',
            '@</?((label)|(select)|(optgroup)|(option)|(textarea))@iu',
            '@</?((frameset)|(frame)|(iframe))@iu',
        ),
        array(
            ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
            "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0",
            "\n\$0", "\n\$0",
        ),
        $text );
    return strip_tags( $text );
}

function Error($msg)
{
	echo "<h1>Oops..</h1><hr size=1><br>Looks like there is a slight problem at our site.<br>";
	echo "An Email has been sent to <a href='mailto:$technicalemail'>$technicalemail</a><br>";
	echo "The problem will be taken care of as soon as possible.<br>";
	echo "Sorry for the inconvenience and thanks for your support";
	exit;
}

?>
